package com.tom.system.controller;

import com.tom.basic.utils.AjaxResult;
import com.tom.basic.utils.PageList;
import com.tom.system.domain.Systemdictionarytype;
import com.tom.system.query.SystemdictionarytypeQuery;
import com.tom.system.service.ISystemdictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(value = "部门的API",description="部门相关的CRUD功能")
@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {
    @Autowired
    private ISystemdictionarytypeService SystemdictionarytypeService;
    /**
     * @Title: 根据id查询
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @ApiOperation(value = "通过ID查询" )
    @GetMapping("/{id}")
    public Systemdictionarytype loadById(@ApiParam(value = "ID属性",required = true) @PathVariable("id")Long id){
        return SystemdictionarytypeService.loadById(id);
    }

    /**
     * @Title: 查询所有
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @GetMapping
    public List<Systemdictionarytype> loadAll(){
        return SystemdictionarytypeService.loadAll();
    }
    /**
     * @Title: 高级查询
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @PostMapping
    public PageList<Systemdictionarytype> queryData(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery) {
        return SystemdictionarytypeService.queryData(systemdictionarytypeQuery);
    }
    /**
     * @Title: 根据id删除
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id")Long id){
        try {
            SystemdictionarytypeService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
        }
    }
    /**
     * @Title: 增加和删除
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @PutMapping
    public AjaxResult updateOrAdd(@RequestBody Systemdictionarytype systemdictionarytype) {
        try {
            if (systemdictionarytype.getId() == null){
                SystemdictionarytypeService.save(systemdictionarytype);
            } else {
                SystemdictionarytypeService.update(systemdictionarytype);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
        }
    }
    /**
     * @Title: 批量删除
     * @Description: TODO
     * @Author: LT
     * @Version: 1.0
     * @Date:
     * @Parameters:
     * @Return
     */
    @PatchMapping
    public AjaxResult batchDel(@RequestBody Long ids[]){
        try {
            SystemdictionarytypeService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后重试");
        }

    }
}
